'<ADbasic Header, Headerversion 001.001>
' Process_Number                 = 1
' Initial_Processdelay           = 100
' Eventsource                    = External
' Control_long_Delays_for_Stop   = No
' Priority                       = High
' Version                        = 1
' ADbasic_Version                = 5.0.6
' Optimize                       = Yes
' Optimize_Level                 = 1
' Info_Last_Save                 = IUTIEP  IUTIEP\Particulier
'<Header End>
#INCLUDE ADWPAD.INC
#INCLUDE ADWINPRO.INC


#DEFINE MaxSamples 262143     'taille totale de la memoire par voie
#DEFINE ainadr 2	          ' 2 = AIN-F8/14

#DEFINE CHAN1 1
#DEFINE CHAN2 2
#DEFINE CHAN3 3
#DEFINE CHAN4 4


' PAR_ 1..5
Dim buffersize As Long 
Dim acq_mode As Long
Dim  sampleperiod As Long    ' periode acquisition = 2MHz  T=20*25 ns (high level)
Dim gain As Long   ' gain 
Dim type_trig As Long 
Dim retard as long ' retard acquisition
dim selretard as long ' selection du retard 0: pas selection 1: selection
' local variable
dim status as long
dim chan As Long
dim i as long

dim data_1[MaxSamples] as long 
dim data_2[MaxSamples] as long 
dim data_3[MaxSamples] as long 
dim data_4[MaxSamples] as Long 


INIT:
  buffersize =  PAR_1 ' taille du buffer acquisition <Maxsamples
  acq_mode =    PAR_2  ' mode acquisition en fonction des voies
  sampleperiod = PAR_3 ' 'sampling period
  type_trig =   PAR_4  ' type de trigger
  gain =        PAR_5       ' gain
  retard = PAR_7   '  retard acquisition
  selretard = PAR_8 ' activation du retard  
  
  for i = 1 to buffersize
    data_1[i]=0
    data_2[i]=0
    data_3[i]=0
    data_4[i]=0
  next i
    
  ' initialise gain pour toutes les voies
  For chan = 1 To 4
    set_gain(ainadr,chan,gain)
  NEXT chan
  

  SelectCase type_trig       'type de trigger
    Case 1               
      POKE(20800100h,1) ' trigger sur front montant exclusivement
    Case 2               
      POKE(20800100h,2) ' trigger sur front descendant exclusivement
    Case 3               'If PAR_1 = 2?
      POKE(20800100h,3) ' trigger sur front montant et descendant.
  EndSelect              'End of selection

  RESET_EVENT
  burst_init(ainadr,acq_mode,sampleperiod,buffersize)
EVENT:
  SetLED(ainadr,ad,1)   ' allume LED
  if (selretard=1) then
    Sleep(retard)
  ENDIF
  burst_start(ainadr)
  do
    status=burst_status(ainadr)
  Until (status=0)
  END
finish:
  burst_read(ainadr,CHAN1,1,buffersize,data_1,1)
  burst_read(ainadr,CHAN2,1,buffersize,data_2,1)
  burst_read(ainadr,CHAN3,1,buffersize,data_3,1)
  burst_read(ainadr,CHAN4,1,buffersize,data_4,1)
  SetLED(ainadr,ad,0)   ' eteind LED
  PAR_6 = 0   ' fin de transfert

